//
//  SQLManager.m
//  CoreDataDemo
//
//  Created by liuxiang on 2018/1/6.
//  Copyright © 2018年 liuxiang. All rights reserved.
//

#import "SQLManager.h"
#import "BookModel.h"

@interface SQLManager()

@property (strong, nonatomic) WCTDatabase *database;


@end

@implementation SQLManager

static SQLManager *_sharedSQLManager;

+ (instancetype) sharedSQLManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedSQLManager = [[SQLManager alloc] init];
        NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"book" ofType:@"db"];
        _sharedSQLManager.database = [[WCTDatabase alloc] initWithPath:dbPath];
    });
    return _sharedSQLManager;
}

- (NSArray<BookModel *> *) findBook {
    NSArray<BookModel *> *result = [self.database getObjectsOfClass:BookModel.class fromTable:@"bc_books" orderBy:BookModel.bookId.order()];
    return result;
}

@end
